function info() {
	if ((navigator.userAgent
			.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
		return 'col-xs-12';
	} else {
		return 'col-sm-3';
	}
}
var ob = {
	
	boxBg : '#ffffff',
	modalBg : 'rgba(0,0,0,0.5)',
	modalHide : false,
	autoShow : false,
	iframeId : 'iframeHBox',
	effect : 'zoomOut',
	isOverlay :true,
	positions : 'top',
	beforeShow : function() {
		var now = $('.now').val();
		var nowms = $('.nowms').val();
		var t = new Date();
		if (now == "" || now == null) {
			$('.now').val(t.format("yyyy-MM-dd"));
		}
		if (nowms == "" || nowms == null) {
			$('.nowms').val(t.getTime());
		}
	},
	afterHide : function() {
		$(ob.box.replace("HBox", "Form") + " .clean_c").val("");
	}
};
function closehd(o, T) {
	var $o = o.autoShow ? T : $(o.box);
	$o.removeAttr('class').addClass('animated ' + o.effect);
	$o.hasClass(o.effect) && setTimeout(function() {
		$o.removeAttr('style').hide();
	}, 300);
	$('#HOverlay,#HTitle,#' + o.iframeId).remove();
	$(ob.box.replace("HBox", "Form") + " .clean_c").val("");
}
var method;
function init(type, width, height, ID, title, DID) {
	var method = "";
	var controller = "../" + type + "Controller/";
	var hbox = '#' + type + 'HBox';
	sethDialog('#add' + type, '添加' + title, hbox, width, height, 0, ID);
	
	sethDialog('#modify' + type, '修改' + title, hbox, width, height, 1, ID);
	$('#add' + type).click(function() {
		$("#ProjectCombox_paper").removeAttr("disabled");
		removeClass(type);
		$("#project_extend1").val("");
		method = "add.action";
		if(type=="User"){
			$("#pwd_hdlog").css("display","block");
			$("#userId").attr("disabled", false);
		}
	});
	$('#modify' + type).click(function() {
		var id = getIdSelections(type, ID);
		if(type=="User"){
			$("#pwd_hdlog").remove();
			$("#userId").attr("disabled", true);
		}
		if (id.length == 1) {
			removeClass(type);
			method = "update.action";
			var obj = $('#' + type).bootstrapTable('getRowByUniqueId', id);
			loadData(obj, '#' + type + 'HBox');
			$("#ProjectCombox_paper").attr("disabled",true);
			$("#passwordUser").val("");
			// $("#extend1").val(2);
			/** **************************************************************************修改处****************** */
		} else {
			toastr.warning("请选择一条记录进行操作!");
		}
		
	});
	
	$('#search' + type).click(function() {
		refresh(type);
	});
	$('#submit' + type).click(
			function() {
				$("#" + type + "Form").valid() ? $(function() {
					if (method == "add.action") {
						submitData_add("#" + type + "Form",
								controller + method, type);
					} else {
						submitData_update("#" + type + "Form", controller
								+ method, type);
					}
				}) : toastr.warning("请填写完整的信息!");
			});
	
	
	$('#delete' + type).click(function() {
		var ids = getIdSelections(type, ID);
		
		if (ids.length > 0) {
			$.ajax({
				url : controller + 'delete.action',
				data : {
					ids : ids.join(','),
					deletestate:1,
				},
				dataType : 'json',
				success : function(d) {			
					
					$('#' + type).bootstrapTable('refresh');
					if (d.success != "0" && typeof (d.success) != "undefined") {
						toastr.success("成功删除" + d.success + "条!");
					}
					if (typeof (d.success) == "undefined") {
						toastr.success("成功删除" + ids.length + "条!");
					}
				}
			});
		} else {
			toastr.warning("请勾选删除的记录!");
		}
	});
}



function refresh(type) {
	$('#' + type).bootstrapTable('refresh');
}
function removeClass(type) {
	$('#' + type + 'HBox').removeClass('btn btn-info');
}

/**
 * 修改
 * 
 * @param type
 */
function removeClassOut(type) {
	$('#' + type + 'OutHBox').removeClass('btn btn-info');
}

function submitData_add(form, url, type, state) {
	$.ajax({
		type : "POST",
		url : url,
		data : $(form).serialize(),
		success : function(data) {	
		
			var hbox = '#' + type + 'HBox';
			ob.box = hbox;
			closehd(ob, $(hbox));
			var obj = JSON.parse(data);
			if (obj.error_user_code == 500) {
				$('#' + type).bootstrapTable('uncheckAll');
				toastr.error("该账号已经被注册了!");
			
			} else {
			
				$('#' + type).bootstrapTable('selectPage', 1);
				$('#' + type).bootstrapTable('insertRow', {
					index : 0,
					row : obj.data
				});
				
				$('#' + type).bootstrapTable('refresh');
				$('#' + type).bootstrapTable('uncheckAll');
				toastr.success("添加成功!");
			}
		},
		error : function(request) {
		    toastr.error("操作失败555555555555555!");
		}
	});
}
function submitData_update(form, url, type, state) {
	$.ajax({
		type : "POST",
		url : url,
		data : $(form).serialize(),
		success : function(data) {
			var hbox = '#' + type + 'HBox';
			ob.box = hbox;
			closehd(ob, $(hbox));
			var obj = JSON.parse(data);
			$('#' + type).bootstrapTable('updateByUniqueId', {
				id : obj.redata,
				row : obj.data
			});
			$('#' + type).bootstrapTable('refresh');
			$('#' + type).bootstrapTable('uncheckAll');
			toastr.success("修改成功!");
		},
		error : function(request) {
			toastr.error("操作失败!");
		}
	});
}
function sethDialog(obj, title, hBox, width, height, type, uid) {
	ob.type = type;
	ob.uid = uid;
	ob.title = title;
	ob.box = hBox;
	ob.height = height;
	ob.width = width;
	$(obj).hDialog(ob);
}

function getIdSelections(type, parm) {
	return $.map($('#' + type).bootstrapTable('getSelections'), function(row) {
		return eval('row.' + parm);
	});
}

function loadData(obj, HBox) {
	// var obj = eval("(" + jsonStr + ")");
	var key, value, tagName, type, arr;
	for (x in obj) {
		key = x;
		value = obj[x];
		$(HBox + " [name='" + key + "']," + HBox + " [name='" + key + "[]']")
				.each(function() {
					tagName = $(this)[0].tagName;
					type = $(this).attr('type');
					if (tagName == 'INPUT') {
						if (type == 'radio') {
							$(this).attr('checked', $(this).val() == value);
						} else if (type == 'checkbox') {
							arr = value.split(',');
							for ( var i = 0; i < arr.length; i++) {
								if ($(this).val() == arr[i]) {
									$(this).attr('checked', true);
									break;
								}
							}
						} else {
							$(this).val(value);
						}
					} else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {
						$(this).val(value);
					}
				});
	}
}

function Combox(type, parm, data) {
	$.ajax({
		type : "POST",
		url : "../" + type + "Controller/conditionSearch.action",
		data : data,
		success : function(data) {
			var html = "<option value=''>-请选择-</option>";
			$.each(JSON.parse(data), function(j, o) {
				html += '<option value="' + eval("o." + parm.id) + '">'
						+ eval("o." + parm.name) + '</option>';
			});
			$("#" + type + "Combox").html(html);
			initSelect2(parm.width);
		},
		error : function(request) {
			toastr.error("操作错误!");
		}
	});
}

function Combox2(type, parm, data) {
	$.ajax({
		type : "POST",
		url : "../" + type + "Controller/conditionSearch.action",
		data : data,
		success : function(data) {
			var html = "<option value=''>-请选择-</option>";
			$.each(JSON.parse(data), function(j, o) {
				html += '<option value="' + eval("o." + parm.id) + '">'
						+ eval("o." + parm.code) + "    "
						+ eval("o." + parm.name) + '</option>';
			});
			$("#" + type + "Combox").html(html);
			initSelect2(parm.width);
		},
		error : function(request) {
			toastr.error("操作错误!");
		}
	});
}
function Combox3(type, parm, data) {
	$.ajax({
		type : "POST",
		url : "../" + type + "Controller/conditionSearch.action",
		data : data,
		success : function(data) {
			var html = "<option value=''>-请选择-</option>";
			$.each(JSON.parse(data), function(j, o) {
				html += '<option value="' + eval("o." + parm.id) + '">'
						+ eval("o." + parm.code) + "    "
						+ eval("o." + parm.name) + '</option>';
			});
			$("#" + type + "Combox2").html(html);
			initSelect2(parm.width);
		},
		error : function(request) {
			toastr.error("操作错误!");
		}
	});
}
function initSelect2(width) {
	$('.select-category').select2();
	$('.select2').css('width', width);
	$('.selection').css('width', width);
	$('.select2-selection').css('width', '100%');
}
function formatDate(time) {
	var date = "";
	var D = "";
	if (time != 0) {
		if (time != undefined) {
			date = new Date(time);
			//alert(date);
		} else {
			date ="";	
		}
		var y = date.getFullYear();
		var M = date.getMonth() < 10 ? '0' + (date.getMonth() + 1) : (date
				.getMonth() + 1);
		var d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
		D = y + "-" + M + "-" + d;
	}

	return D;
}
function formatTime(time) {
	var date = "";
	var T = "";
	if (time != 0) {
		if (time != undefined) {
			date = new Date(time);
		} else {
			date = new Date();
		}
		var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
		var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date
				.getMinutes();
		var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date
				.getSeconds();
		T = h + ":" + m + ":" + s;
	}
	return T;
}
function formatDT(time) {
	var DTime = "";
	if (time != 0) {
		var date = new Date(time);
		var y = date.getFullYear();
		var M = date.getMonth() < 10 ? '0' + (date.getMonth() + 1) : (date
				.getMonth() + 1);
		var d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
		var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
		var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date
				.getMinutes();
		var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date
				.getSeconds();
		DTime = y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s;
	}
	return DTime;
}


/*
 * $.validator.addMethod("string", function(value, element) { return
 * this.optional(element) || /^[u0391-uFFE5w]+$/.test(value); }, "不允许包含特殊符号!");
 */

// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.format = function(fmt) { // author: meizz
	var o = {
		"M+" : this.getMonth() + 1, // 月份
		"d+" : this.getDate(), // 日
		"h+" : this.getHours(), // 小时
		"m+" : this.getMinutes(), // 分
		"s+" : this.getSeconds(), // 秒
		"q+" : Math.floor((this.getMonth() + 3) / 3), // 季度
		"S" : this.getMilliseconds()
	// 毫秒
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	for ( var k in o)
		if (new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
					: (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
};

function workP(pattern) {
	return eval("workPattern.workPattern" + pattern);
}

function parmname(parm) {
	return eval("parms." + parm);
}

function warningCode(parm) {
	return eval("warningcode.warningcode" + parm);
}

function subtaskStatus(parm) {
	return eval("subtaskstatus.status" + parm);
}
